package com.sitech.ibnms.util.charts.fusion;

import java.util.List;
import java.util.Map;

import com.sitech.ibnms.util.charts.domain.HIS_DATA_DOMAIN;
import com.sitech.ibnms.util.charts.fusion.line.FusionLineChartParameter;

public class FusionLineChart {
	/**
	 * @param map
	 * @return
	 */
	public StringBuffer setLineChartParameter(FusionLineChartParameter parameter,List<HIS_DATA_DOMAIN> hisData){
		/**
		 * <chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' 
		 * yAxisMinValue='15000'  numberPrefix='$' showValues='0' alternateHGridColor='FCB541' alternateHGridAlpha='20' 
		 * divLineColor='FCB541' divLineAlpha='50' canvasBorderColor='666666' baseFontColor='666666' lineColor='FCB541'>
		 * alternateHGridColor='"+color+"' alternateHGridAlpha='20' 
		 * canvasBorderColor='"+color+"'
		 *  baseFontColor='"+color+"'
		 */
		String color = (String)parameter.getLineColor();
		StringBuffer rsBuffer = new StringBuffer();
		rsBuffer.append(" <chart " +
				" palette='"+parameter.getPalette()+"'" +
				" bgColor='"+parameter.getBgColor()+"'"+
				" caption='"+parameter.getCaption()+"'" +
				" subCaption='"+parameter.getSubCaption()+"' " +
				" yAxisName='"+parameter.getYAxisName()+"'" +
				" rotateYAxisName='"+parameter.getRotateYAxisName()+"'"+
				" xAxisName='"+parameter.getXAxisName()+"'"+
				" showBorder='"+parameter.getShowBorder()+"'"+
				" numberSuffix='"+parameter.getNumberSuffix()+"' showLimits='0' yAxisMinValue='"+parameter.getYAxisMinValue()+"'" +
						" yAxisMaxValue='"+parameter.getYAxisMaxValue()+"' showValues='0' " +
				" divLineColor='"+color+"' divLineAlpha='50' labelDisplay='"+parameter.getLabelDisplay()+"' " +
				" lineThickness='"+parameter.getLineThickness()+"'"+
				" showShadow='"+parameter.getShowShadow()+"'"+
				" lineColor='5EE559'>" +
				"");
		
		rsBuffer.append(this.setLinChartGraphValue(hisData));
		rsBuffer.append(this.setStyle());
		rsBuffer.append("</chart>");
		
		return rsBuffer;
	}
	/**
	 * ͨ����ʷ��¼���ͼ�������б?ֻʹ��������ͼ
	 * @param hisHostCpu
	 * @return
	 */
	public String setLinChartGraphValue(List<HIS_DATA_DOMAIN> hisData){
		StringBuffer strBuffer = new StringBuffer();
		int size = hisData.size();
		if(size>0){
			for(HIS_DATA_DOMAIN hisHostCpuMap : hisData){
				String cll_date = ((String) hisHostCpuMap.getCLL_TIME()).substring(11);
				String cll_value = (hisHostCpuMap.getKPI_VALUE() != null) ? hisHostCpuMap.getKPI_VALUE().toString():"0";
				strBuffer.append(" <set label='"+cll_date+"' value='"+cll_value+"' showValue='0' showLabel='0'/>");
			}
		}
		
		return strBuffer.toString();
	}
	
	public String setStyle(){
		
		StringBuffer str = new StringBuffer();
		str.append("<styles>");
		str.append("<definition>");
		str.append("<style name='CanvasAnim' type='animation' param='_xScale' start='0' duration='1' />");
		str.append("<style name='fontStyle' type='font' size='12'/>");
		str.append("</definition>");
		str.append("<application>");
		str.append("<apply toObject='Canvas' styles='CanvasAnim' />");
		str.append("<apply toObject='caption' styles='fontStyle' />");
		str.append("<apply toObject='subCaption' styles='fontStyle' />");
		str.append("<apply toObject='xAxisName' styles='fontStyle' />");
		str.append(" </application>   ");
		str.append("</styles>");
		return str.toString();
	}
	
	public String getLineChart(FusionLineChartParameter parameter,List<HIS_DATA_DOMAIN> hisData){
		return  FusionChartCommon.getScript(parameter).replaceAll("######", 
				this.setLineChartParameter(parameter, hisData).toString());
	}
	
}
